package cn.itsource.inter;

import cn.itsource.mapper.PermissionMapper;
import cn.itsource.pojo.bo.PermBo;
import cn.itsource.pojo.domain.Permission;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 📖：beishan
 * 🗓️：2024/4/1 19:27
 * =====================
 * 启动时运行 将获取的数据保存到redis
 */
@Component
public class GatewayListener implements ApplicationListener<ContextClosedEvent> {
    @Autowired
    private PermissionMapper permissionMapper;

    @Autowired
    private     RedisTemplate<String,Object> redisTemplate;
    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        List<PermBo> permBo = permissionMapper.selectPerm(new LambdaQueryWrapper<PermBo>());
        //将获取的 数据 存放在redis
        redisTemplate.opsForValue().set("permissionMsg",permBo);
    }
}
